<?php
/**
 * @brief shop_result_free protocol
 *
 * @param post uid User ID
 * @return money, time_free
 * @author con100 <con100@playplus.net>
 * @since 15/04/2013
 * @copyright Copyright (c) 2013, PlayPlus
 **/

include 'dbconn.php';
include 'include.php';

$user_id = mysql_real_escape_string($_POST['uid']);
$sql = "select timestemp_free, money from ebs_member where id='$user_id'";
$res = mysql_query($sql);
$data = mysql_fetch_assoc($res);

srand((double)microtime()*1000000);

//free 뽑기 가능 여부
if((time()-$data['timestemp_free']) >= (4*60*60)){
	$free = 1;
}else{
	$free = 0;
}

if($free){
	$r = rand(0, 4);

	switch($r){
		case 0 : $bonus_coin = 50; break;
		case 1 : $bonus_coin = 50; break;
		case 2 : $bonus_coin = 100; break;
		case 3 : $bonus_coin = 250; break;
		case 4 : $bonus_coin = 600; break;
	}
	if($bonus_coin){
		$data['money'] += $bonus_coin;
		$time = time();
		$sql = "update ebs_member set money='$data[money]', timestemp_free='$time' where id='$user_id'";
		$res = mysql_query($sql);
		$result = array("Result"=>TRUE, "money"=>$data['money'], "time_free"=>$time);
	}	
}
else{
	$result = array("Result"=>FALSE);
}
echo json_encode($result);
/*
//국비 조회
$no_nation = $data[nation];
if($no_nation != 0){
	$sql = "select * from ebs_nation where no='$no_nation'";
	$res = mysql_query($sql);
	$nation = mysql_fetch_array($res);
}
//국비에 쌓임
if($no_nation != 0){
	$nation[money] -= $bonus_coin;
	if($nation[money] < 0){
		$nation[money] = 0;
	}
	$sql = "update ebs_nation set money='".$nation[money]."' where no='$no_nation'";
	$res = mysql_query($sql);
}
*/
?>